import vehicleInformation from "../assets/vehicleInformation.js";
// 车辆接口列表
export default function (router, DBserve) {
  // 检测m3u8源数据
  DBserve({
    DBname: "vehicleInformation",
    order: "count",
    option: {},
  }).then((data) => {
    // res.json(data);
    if (data.code == 200 && data.data == 0) {
      DBserve({
        DBname: "vehicleInformation",
        order: "insert",
        option: vehicleInformation,
      }).then((data) => {
        if (data.code == 200) console.log("插入车辆源数据");
      });
    }
  });
  router.post("/vehicleInformation", (req, res) => {
    DBserve({
      DBname: "vehicleInformation",
      order: "find",
      option: {},
    }).then((data) => {
      data.data = data.data.sort((a, b) =>
        a.vehicleId.localeCompare(b.vehicleId)
      );
      res.json(data);
    });
  });
  // 修改
  router.post("/update/vehicleInformation", (req, res) => {
    DBserve({
      DBname: "vehicleInformation",
      order: "update",
      option: Object.assign(req.body),
    }).then((data) => {
      res.json(data);
    });
  });
}
